package com.greenlife.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.greenlife.commom.ResponseException;
import com.greenlife.common.enums.BaseResultCodeEnum;
import com.greenlife.common.enums.ShopTypeEnum;
import com.greenlife.dao.ShopMapper;
import com.greenlife.model.Shop;
import com.greenlife.service.ShopService;

@Service("shopService")
public class ShopServiceImpl implements ShopService {

	@Autowired
	private ShopMapper shopMapper;

	@Override
	public int deleteByPrimaryKey(Shop shop) {
		int value = shopMapper.deleteByPrimaryKey(shop);
		if (value == 1) {
			return 1;
		} else {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_40000);
		}
	}

	@Override
	public Shop insertSelective(Shop shop) {
		try {
			shop.setRunningType(ShopTypeEnum.CHECKED);
			int value = shopMapper.insertSelective(shop);
			if (value == 1)
				return shop;
			else
				throw new ResponseException(BaseResultCodeEnum.ERR_CODE_30009);
		} catch (Exception e) {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_30009);
		}
	}

	@Override
	public Shop selectByPrimaryKey(Shop shop) {
		Shop value = shopMapper.selectByPrimaryKey(shop);
		if (value == null) {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_40000);
		}
		return value;
	}

	@Override
	public int updateByPrimaryKeySelective(Shop shop) {
		int value = shopMapper.updateByPrimaryKeySelective(shop);
		if (value == 1) {
			return value;
		} else {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_10001);
		}
	}

	@Override
	public List<Shop> selectByUserId(Shop shop) {

		return shopMapper.selectByUserId(shop);
	}

}